libostree: set directory mtimes to 0 on checkout
authorDaniel Drake <drake@endlessm.com>
Wed, 18 Feb 2015 23:18:21 +0000 (17:18 -0600)
committerColin Walters <walters@verbum.org>
Wed, 18 Feb 2015 23:27:18 +0000 (18:27 -0500)
We already set all file mtimes to 0 so that they are constant
over all checkouts, and can be made constant with a known value from
the system where the ostree was created.

However, this was not happening for directories. Zero their mtimes too.

This is important for shipping a fontconfig cache in the ostree;
the fontconfig cache files embed a directory mtime.

src/libostree/ostree-repo-checkout.c
tests/basic-test.sh

index 1340484cf386d904be396bbf84346c25b8265716..bbb3f11d471435561c5e0f9494792cffd07c5937 100644 (file)
@@ -691,6 +691,22 @@ checkout_tree_at (OstreeRepo                        *self,
         }
     }
 
+  /* Set directory mtime to 0, so that it is constant for all checkouts.
+   * Must be done after setting permissions and creating all children.
+   */
+  if (!did_exist)
+    {
+      const struct timespec times[2] = { { 0, UTIME_OMIT }, { 0, } };
+      do
+        res = futimens (destination_dfd, times);
+      while (G_UNLIKELY (res == -1 && errno == EINTR));
+      if (G_UNLIKELY (res == -1))
+        {
+          gs_set_error_from_errno (error, errno);
+          goto out;
+        }
+    }
+
   /* Finally, fsync to ensure all entries are on disk.  Ultimately
    * this should be configurable for the case where we're constructing
    * buildroots.
index 106d9f120d2fd57d08f4754d3bab863c279d83c9..007d7ced5486c3387c7785573e0e38c31ffc92f2 100755 (executable)
@@ -347,6 +347,8 @@ else
 fi
 stat '--format=%Y' test2-checkout/baz/cow > cow-mtime
 assert_file_has_content cow-mtime 0
+stat '--format=%Y' test2-checkout/baz/deeper > deeper-mtime
+assert_file_has_content deeper-mtime 0
 echo "ok content mtime"
 
 cd ${test_tmpdir}